package com.benyi.byiee.model.api;

import com.benyi.byiee.model.db.UserAccount;

public class User {
	 
    private String email;   
    private long lastTime;
    private String fromIp; 
    private String token; 
    
    private Long currentCompany=0L;
    
    private UserAccount account;
     
    
	public UserAccount getAccount() {
		return account;
	}

	public void setAccount(UserAccount account) {
		this.account = account;
	}

	public Long getCurrentCompany() {
		return currentCompany;
	}

	public void setCurrentCompany(Long currentCpmoany) {
		this.currentCompany = currentCpmoany;
	} 

	public String getToken() {
		return token;
	}
	
	public void setToken(String token) {
		this.token = token;
	} 
	
	public String getEmail() {
		return email;
	}
	
	public void setEmail(String email) {
		this.email = email;
	} 
	
	public long getLastTime() {
		return lastTime;
	}
	
	public void setLastTime(long lastTime) {
		this.lastTime = lastTime;
	}
	
	public String getFromIp() {
		return fromIp;
	}
	
	public void setFromIp(String fromIp) {
		this.fromIp = fromIp;
	}
    
    public void fresh() {
    	lastTime = System.currentTimeMillis();
    } 
    
    public boolean isValid(String ip,int maxTime) {
    	long  t = (System.currentTimeMillis() - lastTime)/1000 ;
    	if(t > maxTime) {
    		return false;
    	}
    	if(ip==null || fromIp == null) {
    		return false;
    	}
    	if(fromIp.equals(ip)) {
    		return true;
    	}
    	return false;
    }
    
    public boolean isExpired(int maxTime) {
    	long  t = (System.currentTimeMillis() - lastTime)/1000 ;
    	if(t > maxTime) {
    		return true;
    	} 
    	return false;
    }
    
}
